<?php

/**
 * 操作日志
 *
 * @author JiangJian <silverd@sohu.com>
 * @copyright 2011-2012 xiangle.com
 * $Id: OpLog.php 162 2012-11-09 04:04:30Z Jun.Lu.726@gmail.com $
 * @version    2012-02-16  ::  JiangJian  ::  Create File
 */
class Controller_System_OpLog extends Controller_Abstract
{

    private $_log;
    private $_opTypes;

    public function init()
    {
        parent::init();
        $this->_log = Model('System_OpLog');

        // 操作类型集
        $this->_opTypes = $this->_log->getOpTypes();
        $this->assign('opTypes', $this->_opTypes);
    }

    /**
     * 操作日志查询列表
     */
    public function indexAction()
    {
        // 列表分页
        $pageSize = 20;
        $page     = max(1, intval($this->get('page')));
        $start    = ($page - 1 ) * $pageSize;

        // 搜索参数
        $params = array();
        $whereSql = '1';

        // 赋初值
        $list      = $multipage = '';

        // 按城市
        $cityId = intval($this->get('city_id'));
        if ($cityId) {
            $whereSql .= " AND city_id = '{$city_id}'";
            $params['city_id'] = $cityId;
        }

        // 按操作类型
        $type = trim($this->get('type'));
        if ($type) {
            $whereSql .= " AND type = '{$type}'";
            $params['type'] = $type;
        }

        // 按操作人
        $adminName = trim($this->get('admin_name'));
        if ($adminName) {
            $whereSql .= " AND admin_name = '{$adminName}'";
            $params['admin_name'] = $adminName;
        }

        // 按起始时间
        $startDate = trim($this->get('start_date'));
        $startTime = strtotime($startDate);
        if ($startTime) {
            $whereSql .= " AND create_time >= '{$startTime}'";
            $params['start_date'] = $startDate;
        }

        $endDate = trim($this->get('end_date'));
        $endTime = strtotime($endDate);
        if ($endTime) {
            $endTime += 86399;
            $whereSql .= " AND create_time <= '{$endTime}'";
            $params['end_date'] = $endDate;
        }

        // 查询
        $count = $this->_log->count($whereSql);
        if ($count) {
            $list      = $this->_log->findByPage($whereSql, $start, $pageSize);
            $multipage = Com_Pager::admincp($count, $pageSize, $page, '/_system/op-log/', $params);
        }

        $this->assign(array(
            'params'    => $params,
            'count'     => $count,
            'list'      => $list,
            'multipage' => $multipage,
        ));
       // $this->render('system/oplog_list');
    }

}